/*
 * crash_protocol_packet.cpp
 *
 *  Created on: 07.07.2013
 *      Author: SpirTanol
 */

#include "packets/crash_protocol_packet.h"
//=========================================================================================
CrashProtocolPacket::CrashProtocolPacket(const CrashProtocolPacket *packet)
{
	init(packet->oCurScale);
	memcpy(oData, packet->oData, R_SIZE * sizeof(ushort) * 10);
}
//=========================================================================================
CrashData CrashProtocolPacket::crash(int idx) const
{
	CrashData data;
	data.oCode = int(oData[R_SIZE * idx + R_CODE]);
	data.oTime = *(uint*)&oData[R_SIZE * idx + R_TIME];

	data.oCur[P_A] = double(oData[R_SIZE * idx + R_CUR + P_A]) / oCurScale;
	data.oCur[P_B] = double(oData[R_SIZE * idx + R_CUR + P_B]) / oCurScale;
	data.oCur[P_C] = double(oData[R_SIZE * idx + R_CUR + P_C]) / oCurScale;

	data.oVol[P_A] = uint(oData[R_SIZE * idx + R_VOL + P_A]);
	data.oVol[P_B] = uint(oData[R_SIZE * idx + R_VOL + P_B]);
	data.oVol[P_C] = uint(oData[R_SIZE * idx + R_VOL + P_C]);

	return data;
}
